<?php

namespace app\api\controller;

use app\common\controller\Api;

/**
 * 信息首页接口
 */
class News extends Api
{
    protected $noNeedLogin = [''];
    protected $noNeedRight = ['*'];
    public $url='http://192.168.3.104/zhaogong/public';

    /**
     * 首页
     *
     */
    public function index()
    {   
        //类型  消息类型:1=通知,2=活动
        $data=input('data');
        if($data){
            $where['data']=$data;
        }else{
            $where='';
        }
        $limit=input('limit')?input('limit'):10;
        $page=input('page')?input('page'):1;
        $list=db('News')->field('id,title,createtime,data')->order('createtime desc')->where($where)->page($page,$limit)->select();
        foreach($list as $k=>$v){
            $list[$k]['createtime']=date('Y-m-d',$v['createtime']);
        }
        $this->success('查询成功',$list);
    }
    /**
     * 消息详情
     */
    public function newsDetail(){
        $id=input('id');
        $where['id']=$id;
        $list=db('News')->where($where)->find();
        $list['content']=str_replace('<img src="', '<img src="'.$this->url, $list['content']);
        $this->success('查询成功',$list);
    }
    /**
     * 实名认证页面展示
     */
    public function criect(){
        $user = $this->auth->getUserinfo();
        $user_id=$user['id'];
        $user = db('user')->where(['id'=>$user_id])->find();
        $data['username'] = $user['username'];
        if($user['sfz_image']){
            $data['sfz_image'] = $user['sfz_image'];
        }else{
            $data['sfz_image'] = '/image/head_img_03.png';
        }
        if($user['sfz1_image']){
            $data['sfz1_image'] = $user['sfz1_image'];
        }else{
            $data['sfz1_image'] = '/image/head_img_03.png';
        }
        $data['idcarnum'] = $user['idcarnum'];
        $this->success('查询成功',$data);
    }
    /**
     * 实名认证
     */
    public function criectfun(){
        $user = $this->auth->getUserinfo();
        $user_id=$user['id'];
        $sfz_image = input('sfz_image')?input('sfz_image'):'';
        $sfz1_image = input('sfz1_image')?input('sfz1_image'):'';
        if(empty($sfz_image) || $sfz_image=='/image/head_img_03.png'){
            $this->error('请上传身份证正面');
        }
        if(empty($sfz1_image) || $sfz1_image=="/image/head_img_03.png"){
            $this->error('请上传身份证反面');
        }
        $idcarnum = input('idcarnum')?input('idcarnum'):'';
        if(empty($idcarnum)){
            $this->error('请输入身份证号码');
        }
        $username = input('username')?input('username'):'';
        if(empty($username)){
            $this->error('请输入真实姓名');
        }
        $data['sfz_image']=$sfz_image;
        $data['sfz1_image']=$sfz1_image;
        $data['idcarnum']=$idcarnum;
        $data['username']=$username;
        $data['is_real']=2;
        db('user')->where(['id'=>$user_id])->update($data);
        $this->success('认证成功');
    }
}
